package com.hbt.android.kotlin.service

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.widget.Toast


class LearnBroadcastReceiver: BroadcastReceiver() {

    /**
     * 广播接收者
     */
    override fun onReceive(context: Context?, intent: Intent?) {
        val action = intent?.action ?: return
        if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) == true) {
            val connectivityManager = context?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
            val info = connectivityManager.activeNetworkInfo
                if (info != null && info.isAvailable) {
                val typeName = info.typeName
                Toast.makeText(context, "当前网络名称:${typeName}", Toast.LENGTH_LONG).show()
            } else {
                Toast.makeText(context, "当前无网络", Toast.LENGTH_LONG).show()
            }
        }else if(action == "com.hbt.android.kotlin.LEARN_BROADCAST_RECEIVER") {
            Toast.makeText(context, "静态注册广播，自定义事件", Toast.LENGTH_LONG).show()
        }
    }
}